# Maintainer: Christoph Reiter <reiter.christoph@gmail.com>

_realname=dosbox
_forkname=dosbox-staging
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=0.80.1
pkgrel=1
pkgdesc="Emulator with builtin DOS for running DOS Games (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
url='https://github.com/dosbox-staging/dosbox-staging'
license=('spdx:GPL-2.0-or-later')
depends=(
    "${MINGW_PACKAGE_PREFIX}-fluidsynth"
    "${MINGW_PACKAGE_PREFIX}-libpng"
    "${MINGW_PACKAGE_PREFIX}-opusfile"
    "${MINGW_PACKAGE_PREFIX}-SDL2"
    "${MINGW_PACKAGE_PREFIX}-SDL2_image"
    "${MINGW_PACKAGE_PREFIX}-SDL2_net"
    "${MINGW_PACKAGE_PREFIX}-zlib"
    "${MINGW_PACKAGE_PREFIX}-libslirp"
    "${MINGW_PACKAGE_PREFIX}-munt-mt32emu"
    "${MINGW_PACKAGE_PREFIX}-speexdsp"
    "${MINGW_PACKAGE_PREFIX}-iir"
)
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config")
source=("https://github.com/dosbox-staging/dosbox-staging/archive/refs/tags/v${pkgver}.tar.gz")
sha256sums=('2ca69e65e6c181197b63388c60487a3bcea804232a28c44c37704e70d49a0392')

prepare() {
  cd "${srcdir}/${_forkname}-${pkgver}"
}

build() {
  mkdir -p build-${MSYSTEM} && cd build-${MSYSTEM}

  declare -a extra_config
  if check_option "debug" "n"; then
    extra_config+=("--buildtype=release")
  else
    extra_config+=("--buildtype=debug")
  fi

  MSYS2_ARG_CONV_EXCL="--prefix=" \
  ${MINGW_PREFIX}/bin/meson \
    --prefix="${MINGW_PREFIX}" \
    --wrap-mode=nodownload \
    --auto-features=enabled \
    "${extra_config[@]}" \
    -Dunit_tests=disabled \
    -Ddefault_library=shared \
    ../${_forkname}-${pkgver}

  ${MINGW_PREFIX}/bin/meson compile
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/meson test
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"

  DESTDIR="${pkgdir}" ${MINGW_PREFIX}/bin/meson install

  install -Dm644 "${srcdir}/${_forkname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
